package com.avengers.modules.spider.whois.bean;

import com.jfinal.ext.kit.DateKit;
import org.joda.time.DateTime;

import java.util.Date;
import java.util.List;

/**
 * @author yu.wang
 * @since 2018-08-12 下午1:52
 */
public class WhoisInfo {
    private String domain;
    /**
     * 域名roid
     */
    private String registryDomainId;
    private String registrarWhoisServer;
    private String registrarUrl;
    private String registrar;
    private String registrarId;
    private String contactId;
    private String contactName;
    private String contactEmail;
    private String contactPhone;
    private String dnsSec;
    private Date updateDate;
    private Date createDate;
    private Date expiryDate;
    /**
     * 是否被保留
     */
    private Boolean isRetained;
    private List<String> statusList;
    private List<String> nameServerList;

    public WhoisInfo(String domain) {
        this.domain = domain;
        this.isRetained = false;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getRegistryDomainId() {
        return registryDomainId;
    }

    public void setRegistryDomainId(String registryDomainId) {
        this.registryDomainId = registryDomainId;
    }

    public String getRegistrarWhoisServer() {
        return registrarWhoisServer;
    }

    public void setRegistrarWhoisServer(String registrarWhoisServer) {
        this.registrarWhoisServer = registrarWhoisServer;
    }

    public String getRegistrarUrl() {
        return registrarUrl;
    }

    public void setRegistrarUrl(String registrarUrl) {
        this.registrarUrl = registrarUrl;
    }

    public String getRegistrar() {
        return registrar;
    }

    public void setRegistrar(String registrar) {
        this.registrar = registrar;
    }

    public String getRegistrarId() {
        return registrarId;
    }

    public void setRegistrarId(String registrarId) {
        this.registrarId = registrarId;
    }

    public String getContactId() {
        return contactId;
    }

    public void setContactId(String contactId) {
        this.contactId = contactId;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getDnsSec() {
        return dnsSec;
    }

    public void setDnsSec(String dnsSec) {
        this.dnsSec = dnsSec;
    }

    public Boolean getRetained() {
        return isRetained;
    }

    public void setRetained(Boolean retained) {
        isRetained = retained;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = transferDate(updateDate);
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = transferDate(createDate);
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(String expiryDate) {
        this.expiryDate = transferDate(expiryDate);
    }

    public List<String> getStatusList() {
        return statusList;
    }

    public void setStatusList(List<String> statusList) {
        this.statusList = statusList;
    }

    public List<String> getNameServerList() {
        return nameServerList;
    }

    public void setNameServerList(List<String> nameServerList) {
        this.nameServerList = nameServerList;
    }

    private Date transferDate(String dateTime) {
        if (null == dateTime || dateTime.isEmpty()) {
            return null;
        }
        if (dateTime.contains("T") && dateTime.endsWith("Z")) {
            return new DateTime(dateTime).toDate();
        }
        return DateKit.toDate(dateTime);
    }
}
